package com.wbdgj.ui.mine;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.services.geocoder.GeocodeAddress;
import com.amap.api.services.geocoder.GeocodeQuery;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.bumptech.glide.Glide;
import com.google.gson.internal.LinkedTreeMap;
import com.igexin.sdk.PushManager;
import com.wbdgj.R;
import com.wbdgj.adapter.FootprintBranchAdapter;
import com.wbdgj.adapter.WbAdapter;
import com.wbdgj.base.BaseApplication;
import com.wbdgj.base.BaseFragment;
import com.wbdgj.base.BaseWhiteFragment;
import com.wbdgj.http.HttpAdapter;
import com.wbdgj.http.OnNoResponseListener;
import com.wbdgj.http.OnResponseListener;
import com.wbdgj.model.ResultObjectModel;
import com.wbdgj.model.ResultUrlModel;
import com.wbdgj.ui.branch.FootprintBranchActivity;
import com.wbdgj.ui.branch.NetfeeRoamingHistoryActivity;
import com.wbdgj.ui.home.ExampleActivity;
import com.wbdgj.ui.home.ExampleListActivity;
import com.wbdgj.ui.home.LoactionActivity;
import com.wbdgj.ui.login.LoginActivity;
import com.wbdgj.ui.uitool.ShareBoard;
import com.wbdgj.ui.uitool.ShareBoardlistener;
import com.wbdgj.ui.uitool.SnsPlatform;
import com.wbdgj.utils.SpKeyUtils;
import com.wbdgj.utils.ToastUtils;
import com.wbdgj.utils.scrollablelayout.ScrollableLayout;
import com.wbdgj.views.AllRoundImageView;
import com.zaaach.citypicker.CityPickerActivity;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import cn.jiguang.share.android.api.JShareInterface;
import cn.jiguang.share.android.api.PlatActionListener;
import cn.jiguang.share.android.api.Platform;
import cn.jiguang.share.android.api.ShareParams;
import cn.jiguang.share.facebook.Facebook;
import cn.jiguang.share.facebook.messenger.FbMessenger;
import cn.jiguang.share.qqmodel.QQ;
import cn.jiguang.share.qqmodel.QZone;
import cn.jiguang.share.twitter.Twitter;
import cn.jiguang.share.wechat.Wechat;
import cn.jiguang.share.wechat.WechatFavorite;
import cn.jiguang.share.wechat.WechatMoments;
import cn.jiguang.share.weibo.SinaWeibo;
import cn.jiguang.share.weibo.SinaWeiboMessage;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrHandler;
import retrofit2.Call;

/**
 * Created by Administrator on 2018/5/2.
 */

public class MineFragment extends BaseWhiteFragment implements PtrHandler{

    private Context context;
    @BindView(R.id.pfl_root)
    PtrClassicFrameLayout pfl_root;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.card)
    TextView card;
    @BindView(R.id.roundImg)
    AllRoundImageView roundImg;

    @BindView(R.id.wsmrz)
    ImageView wsmrz;

    @BindView(R.id.ye)
    TextView ye;
    @BindView(R.id.yhj)
    TextView yhj;
    @BindView(R.id.jf)
    TextView jf;

    @BindView(R.id.levelLay)
    LinearLayout levelLay;
    @BindView(R.id.levelImg)
    ImageView levelImg;

    @BindView(R.id.yqhykLay)
    LinearLayout yqhykLay;

    private Boolean isSm = true;
    private String numCoupon ;
    private String ID;

    private String urlStr;
    private int mAction = Platform.ACTION_SHARE;
    private ShareBoard mShareBoard;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            String toastMsg = (String) msg.obj;
            Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show();
//            if (progressDialog != null && progressDialog.isShowing()) {
//                progressDialog.dismiss();
//            }
        }
    };
    @Override
    protected int getLayout() {
        return R.layout.ui_mine;
    }

    @Override
    protected void onInit() {
        context = getActivity();
        pfl_root.setEnabledNextPtrAtOnce(true);
        pfl_root.setLastUpdateTimeRelateObject(this);
        pfl_root.setPtrHandler(this);
        pfl_root.setKeepHeaderWhenRefresh(true);
        getMbUserInfo();
    }

    @Override
    public void onResume() {
        super.onResume();
        getMbUserInfoNo();
        appCouponlist();
        addAttentionList();
        upbranchlist();
    }

    @OnClick({R.id.yqhyLay, R.id.yqhykLay, R.id.grxxLay, R.id.yeLay, R.id.yhjLay, R.id.jfLay, R.id.ewmLay, R.id.yjfkLay, R.id.szLay})
    public void onClick(View view) {
        switch (view.getId()) {

            case R.id.yqhyLay:
                launch(YqhyActivity.class);
                break;
            case R.id.yqhykLay:
                if (ContextCompat.checkSelfPermission(context,
                        android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
                        != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(getActivity()
                            , new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 10);
                    ToastUtils.toastShort("请打开您设备上的照片,媒体内容和文件访问权限!");
                    return;
                }
                createUrl();
                break;
            case R.id.grxxLay:
                if (isSm){
                    launch(VerifiedActivity.class);
                }else{
                    launch(InformaticaNewActivity.class);
                }
                break;
            case R.id.yeLay:
                if (isSm){
                    launch(VerifiedActivity.class);
                }else{
                    launch(MyWbActivity.class);
                }
                break;
            case R.id.yhjLay:
                if (isSm){
                    launch(VerifiedActivity.class);
                }else{
                    startActivity(new Intent(context, YhjActivity.class).putExtra("wsyNum", wsyNum).putExtra("ysyNum", ysyNum).putExtra("ygqNum", ygqNum));
                }

                break;
            case R.id.jfLay:
                if (isSm){
                    launch(VerifiedActivity.class);
                }else{
                    launch(FootprintBranchActivity.class);
                }

                break;

            case R.id.ewmLay:
                if (isSm){
                    launch(VerifiedActivity.class);
                }else{
                    launch(MyEwmActivity.class);
                }

                break;
            case R.id.yjfkLay:
                if (isSm){
                    launch(VerifiedActivity.class);
                }else{
                    launch(YjfkActivity.class);
                }

                break;
            case R.id.szLay:
                launch(SettingActivity.class);
                break;
        }
    }

    private String wsyNum ,ysyNum , ygqNum;

    private void appCouponlist() {
        Call<ResultObjectModel> call01 = HttpAdapter.getSerives().getTotals(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.TOKEN));
        call01.enqueue(new OnNoResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
                    wsyNum = decimalFormat.format(linkedTreeMap.get("UNUSED"));
                    ysyNum = decimalFormat.format(linkedTreeMap.get("USED"));
                    ygqNum = decimalFormat.format(linkedTreeMap.get("DUE"));
                    yhj.setText(wsyNum+"");
                }else if (userModelBaseResultModel.getResultCode().equals("1111")){
                    ToastUtils.toastShort("账号没有登录或在其它地方登录");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.TOKEN, "");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.IS_AUTO_LOGIN, "2");
                    PushManager.getInstance().unBindAlias(context, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.LOGIN_PHONE), false, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CID));
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }
            }
        });

    }

    private void addAttentionList() {
        Call<ResultObjectModel> call = HttpAdapter.getSerives().addAttentionList(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.TOKEN), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.COORDSX), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.COORDSY), "10", "1");
        call.enqueue(new OnNoResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
                    DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                    LinkedTreeMap pageLinkedTreeMap = (com.google.gson.internal.LinkedTreeMap) linkedTreeMap.get("page");
                    ye.setText(Integer.parseInt(decimalFormat.format(pageLinkedTreeMap.get("totalCount")))+"");
                }
            }
        });
    }

    private void upbranchlist() {
        Call<ResultObjectModel> call = HttpAdapter.getSerives().upbranchlist(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.TOKEN));
        call.enqueue(new OnNoResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
                    List<LinkedTreeMap> linkedTreeMaps  = (List<LinkedTreeMap>) linkedTreeMap.get("data");
                    jf.setText(linkedTreeMaps.size()+"");
                }
            }
        });
    }

    private void createUrl() {
        Call<ResultUrlModel> call = HttpAdapter.getSerives().createUrl("200288", ID);
        call.enqueue(new OnResponseListener<ResultUrlModel>(context) {
            @Override
            protected void onSuccess(ResultUrlModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    urlStr =  HttpAdapter.HEAD_URL + userModelBaseResultModel.getUrl();
                    mAction = Platform.ACTION_SHARE;
                    showBroadView();
                }else if (userModelBaseResultModel.getResultCode().equals("1111")){
                    ToastUtils.toastShort("账号没有登录或在其它地方登录");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.TOKEN, "");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.IS_AUTO_LOGIN, "2");
                    PushManager.getInstance().unBindAlias(context, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.LOGIN_PHONE), false, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CID));
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }else{
                    ToastUtils.toastShort(userModelBaseResultModel.getResultMsg());
                }
            }
        });
    }

    private void getMbUserInfo() {
        Call<ResultObjectModel> call = HttpAdapter.getSerives().getMbUserInfo(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.TOKEN));
        call.enqueue(new OnResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
                    if ((linkedTreeMap.get("NAME")+"").equals("null")){
                        wsmrz.setVisibility(View.GONE);
                        name.setVisibility(View.VISIBLE);
                        name.setText("未实名认证");
                        isSm = true;
                    }else if((linkedTreeMap.get("NAME")+"").equals("")){
                        wsmrz.setVisibility(View.GONE);
                        name.setVisibility(View.VISIBLE);
                        name.setText("未实名认证");
                        isSm = true;
                    }else{
                        wsmrz.setVisibility(View.GONE);
                        name.setVisibility(View.VISIBLE);
                        name.setText(linkedTreeMap.get("NAME")+"");
                        isSm = false;
                    }


                    if (linkedTreeMap.containsKey("LEVEL")){
                        if (decimalFormat.format(linkedTreeMap.get("LEVEL")).equals("1")){
                            levelLay.setBackgroundResource(R.mipmap.v_01_bg);
                            levelImg.setBackgroundResource(R.mipmap.v_01);
                            card.setText("普通会员");
                            card.setTextColor(getResources().getColor(R.color.v_01));
                        }else if (decimalFormat.format(linkedTreeMap.get("LEVEL")).equals("2")){
                            levelLay.setBackgroundResource(R.mipmap.v_02_bg);
                            levelImg.setBackgroundResource(R.mipmap.v_02);
                            card.setText("黄金会员");
                            card.setTextColor(getResources().getColor(R.color.v_02));
                        }else if (decimalFormat.format(linkedTreeMap.get("LEVEL")).equals("3")){
                            card.setText("白金会员");
                            card.setTextColor(getResources().getColor(R.color.v_03));
                            levelLay.setBackgroundResource(R.mipmap.v_03_bg);
                            levelImg.setBackgroundResource(R.mipmap.v_03);
                        }else if (decimalFormat.format(linkedTreeMap.get("LEVEL")).equals("4")){
                            card.setText("钻石会员");
                            card.setTextColor(getResources().getColor(R.color.v_04));
                            levelLay.setBackgroundResource(R.mipmap.v_04_bg);
                            levelImg.setBackgroundResource(R.mipmap.v_04);
                        }else if (decimalFormat.format(linkedTreeMap.get("LEVEL")).equals("5")){
                            card.setText("黑钻会员");
                            card.setTextColor(getResources().getColor(R.color.v_05));
                            levelLay.setBackgroundResource(R.mipmap.v_05_bg);
                            levelImg.setBackgroundResource(R.mipmap.v_05);
                        }else if (decimalFormat.format(linkedTreeMap.get("LEVEL")).equals("6")){
                            card.setText("股东会员");
                            card.setTextColor(getResources().getColor(R.color.v_06));
                            levelLay.setBackgroundResource(R.mipmap.v_06_bg);
                            levelImg.setBackgroundResource(R.mipmap.v_06);
                        }else{
                            card.setText("普通会员");
                            card.setTextColor(getResources().getColor(R.color.v_01));
                            levelLay.setBackgroundResource(R.mipmap.v_01_bg);
                            levelImg.setBackgroundResource(R.mipmap.v_01);
                        }
                    }
                    ID = linkedTreeMap.get("ID")+"";
                    if (linkedTreeMap.get("PHONE").equals("18056025603")){
                        yqhykLay.setVisibility(View.VISIBLE);
                    }else{
                        yqhykLay.setVisibility(View.GONE);
                    }

                    if (!(linkedTreeMap.get("IMG")+"").equals("null")){
                        Glide.with(context).load(HttpAdapter.HEAD_URL+linkedTreeMap.get("IMG")).placeholder(R.mipmap.mine_photo).error(R.mipmap.mine_photo).into(roundImg);
                    }else{
                        Glide.with(context).load("").placeholder(R.mipmap.mine_photo).error(R.mipmap.mine_photo).into(roundImg);
                    }
                }else if (userModelBaseResultModel.getResultCode().equals("1111")){
                    ToastUtils.toastShort("账号没有登录或在其它地方登录");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.TOKEN, "");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.IS_AUTO_LOGIN, "2");
                    PushManager.getInstance().unBindAlias(context, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.LOGIN_PHONE), false, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CID));
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }else{
                    ToastUtils.toastShort(userModelBaseResultModel.getResultMsg());
                }
            }
        });
    }

    private void getMbUserInfoNo() {
        Call<ResultObjectModel> call = HttpAdapter.getSerives().getMbUserInfo(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.TOKEN));
        call.enqueue(new OnNoResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
                    if ((linkedTreeMap.get("NAME")+"").equals("null")){
                        wsmrz.setVisibility(View.GONE);
                        name.setVisibility(View.VISIBLE);
                        name.setText("未实名认证");
                        isSm = true;
                    }else if((linkedTreeMap.get("NAME")+"").equals("")){
                        wsmrz.setVisibility(View.GONE);
                        name.setVisibility(View.VISIBLE);
                        name.setText("未实名认证");
                        isSm = true;
                    }else{
                        wsmrz.setVisibility(View.GONE);
                        name.setVisibility(View.VISIBLE);
                        name.setText(linkedTreeMap.get("NAME")+"");
                        isSm = false;
                    }

                    if (linkedTreeMap.containsKey("LEVEL")){
                        if (decimalFormat.format(linkedTreeMap.get("LEVEL")).equals("1")){
                            levelLay.setBackgroundResource(R.mipmap.v_01_bg);
                            levelImg.setBackgroundResource(R.mipmap.v_01);
                            card.setText("普通会员");
                            card.setTextColor(getResources().getColor(R.color.v_01));
                        }else if (decimalFormat.format(linkedTreeMap.get("LEVEL")).equals("2")){
                            levelLay.setBackgroundResource(R.mipmap.v_02_bg);
                            levelImg.setBackgroundResource(R.mipmap.v_02);
                            card.setText("黄金会员");
                            card.setTextColor(getResources().getColor(R.color.v_02));
                        }else if (decimalFormat.format(linkedTreeMap.get("LEVEL")).equals("3")){
                            card.setText("白金会员");
                            card.setTextColor(getResources().getColor(R.color.v_03));
                            levelLay.setBackgroundResource(R.mipmap.v_03_bg);
                            levelImg.setBackgroundResource(R.mipmap.v_03);
                        }else if (decimalFormat.format(linkedTreeMap.get("LEVEL")).equals("4")){
                            card.setText("钻石会员");
                            card.setTextColor(getResources().getColor(R.color.v_04));
                            levelLay.setBackgroundResource(R.mipmap.v_04_bg);
                            levelImg.setBackgroundResource(R.mipmap.v_04);
                        }else if (decimalFormat.format(linkedTreeMap.get("LEVEL")).equals("5")){
                            card.setText("黑钻会员");
                            card.setTextColor(getResources().getColor(R.color.v_05));
                            levelLay.setBackgroundResource(R.mipmap.v_05_bg);
                            levelImg.setBackgroundResource(R.mipmap.v_05);
                        }else if (decimalFormat.format(linkedTreeMap.get("LEVEL")).equals("6")){
                            card.setText("股东会员");
                            card.setTextColor(getResources().getColor(R.color.v_06));
                            levelLay.setBackgroundResource(R.mipmap.v_06_bg);
                            levelImg.setBackgroundResource(R.mipmap.v_06);
                        }else{
                            card.setText("普通会员");
                            card.setTextColor(getResources().getColor(R.color.v_01));
                            levelLay.setBackgroundResource(R.mipmap.v_01_bg);
                            levelImg.setBackgroundResource(R.mipmap.v_01);
                        }
                    }
                    ID = linkedTreeMap.get("ID")+"";
                    if (linkedTreeMap.get("PHONE").equals("18056025603")){
                        yqhykLay.setVisibility(View.VISIBLE);
                    }else{
                        yqhykLay.setVisibility(View.GONE);
                    }

                    if (!(linkedTreeMap.get("IMG")+"").equals("null")){
                        Glide.with(context).load(HttpAdapter.HEAD_URL+linkedTreeMap.get("IMG")).placeholder(R.mipmap.mine_photo).error(R.mipmap.mine_photo).into(roundImg);
                    }else{
                        Glide.with(context).load("").placeholder(R.mipmap.mine_photo).error(R.mipmap.mine_photo).into(roundImg);
                    }
                }else if (userModelBaseResultModel.getResultCode().equals("1111")){
                    ToastUtils.toastShort("账号没有登录或在其它地方登录");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.TOKEN, "");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.IS_AUTO_LOGIN, "2");
                    PushManager.getInstance().unBindAlias(context, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.LOGIN_PHONE), false, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CID));
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }else{
                    ToastUtils.toastShort(userModelBaseResultModel.getResultMsg());
                }
            }
        });
    }


    @Override
    public void fetchData() {

    }


    @Override
    public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
        return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
    }

    @Override
    public void onRefreshBegin(PtrFrameLayout frame) {
        getMbUserInfo();
        appCouponlist();
        addAttentionList();
        upbranchlist();
        pfl_root.refreshComplete();
    }

    private void showBroadView() {
        if (mShareBoard == null) {
            mShareBoard = new ShareBoard(getActivity());
            List<String> platforms = JShareInterface.getPlatformList();
            if (platforms != null) {
                Iterator var2 = platforms.iterator();
                while (var2.hasNext()) {
                    String temp = (String) var2.next();
                    SnsPlatform snsPlatform = createSnsPlatform(temp);
                    mShareBoard.addPlatform(snsPlatform);
                }
            }
            mShareBoard.setShareboardclickCallback(mShareBoardlistener);
        }
        mShareBoard.show();
    }

    private ShareBoardlistener mShareBoardlistener = new ShareBoardlistener() {
        @Override
        public void onclick(SnsPlatform snsPlatform, String platform) {

            switch (mAction) {
                case Platform.ACTION_SHARE:
//                    progressDialog.show();
                    //这里以分享链接为例
                    ShareParams shareParams = new ShareParams();
                    shareParams.setShareType(Platform.SHARE_WEBPAGE);
                    shareParams.setTitle("我正在使用全城VIP赠送尊享会员大礼包，快来领取吧！");
                    shareParams.setText("领取尊享会员大礼包");
                    shareParams.setShareType(Platform.SHARE_WEBPAGE);
                    shareParams.setUrl(urlStr);
                    shareParams.setImagePath(BaseApplication.ImagePath);
                    JShareInterface.share(platform, shareParams, mShareListener);
                    break;
                default:
                    break;
            }
        }
    };

    private PlatActionListener mShareListener = new PlatActionListener() {
        @Override
        public void onComplete(Platform platform, int action, HashMap<String, Object> data) {
            if (handler != null) {
                Message message = handler.obtainMessage();
                message.obj = "分享成功";
                handler.sendMessage(message);
            }
        }

        @Override
        public void onError(Platform platform, int action, int errorCode, Throwable error) {
            Log.e("zp", "error:" + errorCode + ",msg:" + error);
            if (handler != null) {
                Message message = handler.obtainMessage();
                message.obj = "分享失败:" + error.getMessage() + "---" + errorCode;
                handler.sendMessage(message);
            }
        }

        @Override
        public void onCancel(Platform platform, int action) {
            if (handler != null) {
                Message message = handler.obtainMessage();
                message.obj = "分享取消";
                handler.sendMessage(message);
            }
        }
    };

    public static SnsPlatform createSnsPlatform(String platformName) {
        String mShowWord = platformName;
        String mIcon = "";
        String mGrayIcon = "";
        String mKeyword = platformName;
        if (Wechat.Name.equals(platformName)) {
            mIcon = "jiguang_socialize_wechat";
            mGrayIcon = "jiguang_socialize_wechat";
            mShowWord = "jiguang_socialize_text_weixin_key";
        } else if (WechatMoments.Name.equals(platformName)) {
            mIcon = "jiguang_socialize_wxcircle";
            mGrayIcon = "jiguang_socialize_wxcircle";
            mShowWord = "jiguang_socialize_text_weixin_circle_key";

        } else if (WechatFavorite.Name.equals(platformName)) {
            mIcon = "jiguang_socialize_wxfavorite";
            mGrayIcon = "jiguang_socialize_wxfavorite";
            mShowWord = "jiguang_socialize_text_weixin_favorite_key";

        } else if (SinaWeibo.Name.equals(platformName)) {
            mIcon = "jiguang_socialize_sina";
            mGrayIcon = "jiguang_socialize_sina";
            mShowWord = "jiguang_socialize_text_sina_key";
        } else if (SinaWeiboMessage.Name.equals(platformName)) {
            mIcon = "jiguang_socialize_sina";
            mGrayIcon = "jiguang_socialize_sina";
            mShowWord = "jiguang_socialize_text_sina_msg_key";
        } else if (QQ.Name.equals(platformName)) {
            mIcon = "jiguang_socialize_qq";
            mGrayIcon = "jiguang_socialize_qq";
            mShowWord = "jiguang_socialize_text_qq_key";

        } else if (QZone.Name.equals(platformName)) {
            mIcon = "jiguang_socialize_qzone";
            mGrayIcon = "jiguang_socialize_qzone";
            mShowWord = "jiguang_socialize_text_qq_zone_key";
        } else if (Facebook.Name.equals(platformName)) {
            mIcon = "jiguang_socialize_facebook";
            mGrayIcon = "jiguang_socialize_facebook";
            mShowWord = "jiguang_socialize_text_facebook_key";
        } else if (FbMessenger.Name.equals(platformName)) {
            mIcon = "jiguang_socialize_messenger";
            mGrayIcon = "jiguang_socialize_messenger";
            mShowWord = "jiguang_socialize_text_messenger_key";
        }else if (Twitter.Name.equals(platformName)) {
            mIcon = "jiguang_socialize_twitter";
            mGrayIcon = "jiguang_socialize_twitter";
            mShowWord = "jiguang_socialize_text_twitter_key";
        }
        return ShareBoard.createSnsPlatform(mShowWord, mKeyword, mIcon, mGrayIcon, 0);
    }
}
